package com.qingke.oo;

public class MyDate {
	private int year;
	private int month;
	private int day;
	private String[] strMonths={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
	private String[] strDays={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
	private int[] daysInMonths={31,28,31,30,31,30,31,31,30,31,30,31};
	
	public MyDate(){
		
	}
	
	public boolean isLeapYear(int year){
		if(year%100==0){
			if(year%400==0)
				return true;
			return false;
		}else if(year%4==0)
			return true;
		return false;
	}
	
	public boolean isValidDate(int year,int month,int day){
		if(year<1 || year>9999 )
			return false;
		if(this.isLeapYear(year)){
			if(month==2&&(day>29||day<0))
				return false;
			if((month==4||month==6||month==9||month==11)&&(day>30||day<0))
				return false;
			if(day>31||day<0)
				return false;
			return true;
		}else{
			if(month==2&&(day>28||day<0))
				return false;
			if((month==4||month==6||month==9||month==11)&&(day>30||day<0))
				return false;
			if(day>31||day<0)
				return false;
			return true;
		}
	}
	
	public int getDayOfWeek(int year,int month,int day){
		if(month==1)
			month=13;
		if(month==2)
			month=14;
		int weekday = (day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
		return weekday;
	}
	
	public MyDate(int year,int month,int day){
		this.year = year;
		this.month = month;
		this.day = day;
		
	}
	
	public void setDate(int year,int month,int day){
		this.year = year;
		this.month = month;
		this.day = day;
	}
	
	public int getYear(){
		return year;
	}
	
	public int getMonth(){
		return month;
	}
	
	public int getDay(){
		return day;
	}
	
	public void setYear(int year){
		this.year = year;
	}
	
	public void  setMonth(int month){
		this.month = month;
	}
	
	public void setDay(int day){
		this.day = day;
	}
	
	public String toString(){
		int i = this.getDayOfWeek(year, month, day);
		String s = "";
		switch(i){
		case 1: s="Monday"; break;
		case 2: s="Tuesday"; break;
		case 3: s="Wednesday"; break;
		case 4: s="Thursday"; break;
		case 5: s="Friday"; break;
		case 6: s="Saturday"; break;
		case 7: s="Sunday"; break;
		}
		return s+"  "+day+"  "+month+"  "+year;
	}
	
	public MyDate nextDay(){
		
		this.setDay(day+1);
		return this;
	}
	
	public MyDate nextMonth(){
		this.setMonth(month+1);
		return this;
	}
	
	public MyDate nextYear(){
		this.setYear(year+1);
		return this;
	}
	
	public MyDate previousDay(){
		this.setDay(day-1);
		return this;
	}
	
	public MyDate previousMonth(){
		this.setMonth(month-1);
		return this;
	}
	
	public MyDate previousYear(){
		this.setYear(year-1);
		return this;
	}
	
	
}
